import loginLogApi from '@/api/oam/loginLog'
import noticeApi from '@/api/notice/notice'

export default {
  name: 'news',
  data() {
    return {
      listQuery: {
        current: 1,
        size: 20,
        beginTime: undefined,
        endTime: undefined,
        criteria:{
            noticeType:'',
            state:''
        }
      },
      total: 0,
      list: null,
      listLoading: true,
      selRow: {},
      noticeTypeList:[],
      centerDialogVisible:false
    }
  },
  created() {
    this.init()
  },
  methods: {
    init() {
      this.fetchData()
      this.getNoticeType()
    },
    getNoticeType(){
        noticeApi.getNoticeType().then(response=>{
        this.noticeTypeList = response.data
})
    },
    formatDate(originVal) {
        if (!originVal) return ''
        const dt = new Date(originVal);
        const y = dt.getFullYear();
        const m = (dt.getMonth() + 1 + "").padStart(2, "0");
        const d = (dt.getDate() + "").padStart(2, "0");
        const hh = (dt.getHours() + "").padStart(2, "0");
        const mm = (dt.getMinutes() + "").padStart(2, "0");
        const ss = (dt.getSeconds() + "").padStart(2, "0");
        return `${y}-${m}-${d} ${hh}:${mm}:${ss}`;
    },
    fetchData() {
        debugger
      this.listLoading = true
      noticeApi.getList(this.listQuery).then(response => {
        this.list = response.data.records
        this.listLoading = false
        this.total = response.data.total
      })
    },
    search() {
      this.listQuery.page = 1
      this.fetchData()
    },
    reset() {
      this.listQuery.beginTime = ''
      this.listQuery.endTime = ''
      this.listQuery.criteria.noticeType = ''
      this.listQuery.criteria.state = ''
      this.listQuery.page = 1
      this.fetchData()
    },
    handleFilter() {
      this.listQuery.page = 1
      this.fetchData()
    },
    fetchNext() {
      this.listQuery.page = this.listQuery.page + 1
      this.fetchData()
    },
    fetchPrev() {
      this.listQuery.page = this.listQuery.page - 1
      this.fetchData()
    },
    fetchPage(page) {
      this.listQuery.page = page
      this.fetchData()
    },
    changeSize(limit) {
      this.listQuery.limit = limit
      this.fetchData()
    },
    clear() {
      this.$confirm('确定清空本次结果集的数据?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        noticeApi.clear(this.listQuery).then(response => {
          this.$message({
            message: '清空成功',
            type: 'success'
          })
          this.fetchData()
        })
      }).catch(() => {
      })
    },
    show(row){
        this.selRow = row
        this.centerDialogVisible = true
    },
    readNotice(id){
        noticeApi.readNoticeBy(this.selRow.id).then(response => {
            this.fetchData()
            this.centerDialogVisible = false
          }) 
    },
    remove(id){
        if(!id)return
        this.$confirm('确定移除该数据吗?', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
          }).then(() => {
            noticeApi.removeById(id).then(response => {
                this.$message({
                    message: '删除成功',
                    type: 'success'
                  })
                  this.fetchData()
              })
          }).catch(() => {
          })
       
    }

  }
}
